// Legal Notices:
//    Copyright (C) 2008, GuruCE Ltd.
//    ALL RIGHTS RESERVED
//    http://guruce.com
//
// Disclaimer:
//    GuruCE Ltd. makes no warranty of any kind regarding
//    this code.  This code is provided on an "As Is" basis and
//    GuruCE Ltd. will not provide any support assistance,
//    installation, training or other services.
//    GuruCE Ltd. does not provide any updates, enhancements
//    or extensions. GuruCE Ltd. specifically disclaims any
//    warranty of merchantability, non-infringement, fitness for any
//    particular purpose, or any other warranty.
//
//    GuruCE Ltd. disclaims all liability, including liability
//    for infringement of any proprietary rights, relating to use of the
//    code. No license, express or implied, by estoppel or otherwise,
//    to any intellectual property rights is granted herein.
//
//    GuruCE Ltd. has no responsibility under warranty, indemnification
//    or otherwise, for the modification or customization of any GuruCE Ltd.
//    software by GuruCE Ltd., customer, website user or any third party even
//    if such customization and/or modification is done using GuruCE Ltd. tools,
//    training or methods documented by GuruCE Ltd.
//
#pragma once

// Change the following definitions:
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
#define __MODULE__ "TouchC"  // The module name

// Definitions for our debug zones                               
#define ZONE0_TEXT          _T("Init")
#define ZONE1_TEXT          _T("Function")
#define ZONE2_TEXT          _T("Memory")
#define ZONE3_TEXT          _T("")
#define ZONE4_TEXT          _T("")
#define ZONE5_TEXT          _T("")
#define ZONE6_TEXT          _T("")
#define ZONE7_TEXT          _T("")
#define ZONE8_TEXT          _T("")
#define ZONE9_TEXT          _T("")
#define ZONE10_TEXT         _T("")
#define ZONE11_TEXT         _T("")
#define ZONE12_TEXT         _T("")
#define ZONE13_TEXT         _T("Info")
#define ZONE14_TEXT         _T("Warning")
#define ZONE15_TEXT         _T("Error")

// These macros can be used as condition flags for LOGMSG
#define ZONE_INIT           DEBUGZONE(0)
#define ZONE_FUNCTION       DEBUGZONE(1)
#define ZONE_MEMORY         DEBUGZONE(2)
#define ZONE_3              DEBUGZONE(3)
#define ZONE_4              DEBUGZONE(4)
#define ZONE_5              DEBUGZONE(5)
#define ZONE_6              DEBUGZONE(6)
#define ZONE_7              DEBUGZONE(7)
#define ZONE_8              DEBUGZONE(8)
#define ZONE_9              DEBUGZONE(9)
#define ZONE_10             DEBUGZONE(10)
#define ZONE_11             DEBUGZONE(11)
#define ZONE_12             DEBUGZONE(12)
#define ZONE_INFO           DEBUGZONE(13)
#define ZONE_WARNING        DEBUGZONE(14)
#define ZONE_ERROR          DEBUGZONE(15)

// These macros can be used to indicate which zones to enable by default (see RETAILZONES and DEBUGZONES below)
#define ZONEMASK_INIT       ZONEMASK(0)
#define ZONEMASK_FUNCTION   ZONEMASK(1)
#define ZONEMASK_MEMORY     ZONEMASK(2)
#define ZONEMASK_3          ZONEMASK(3)
#define ZONEMASK_4          ZONEMASK(4)
#define ZONEMASK_5          ZONEMASK(5)
#define ZONEMASK_6          ZONEMASK(6)
#define ZONEMASK_7          ZONEMASK(7)
#define ZONEMASK_8          ZONEMASK(8)
#define ZONEMASK_9          ZONEMASK(9)
#define ZONEMASK_10         ZONEMASK(10)
#define ZONEMASK_11         ZONEMASK(11)
#define ZONEMASK_12         ZONEMASK(12)
#define ZONEMASK_INFO       ZONEMASK(13)
#define ZONEMASK_WARNING    ZONEMASK(14)
#define ZONEMASK_ERROR      ZONEMASK(15)

#define RETAILZONES     ZONE_INFO | ZONEMASK_INIT | ZONEMASK_WARNING | ZONEMASK_ERROR
#define DEBUGZONES      RETAILZONES | ZONEMASK_FUNCTION | ZONEMASK_MEMORY | ZONEMASK_INFO

// Define FULL_CONTEXT to show full context in debug messages:
// "Module: [full path to file name:line number] Function>"
//#define FULL_CONTEXT
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/


// Do NOT change any of the following definitions:
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
LPCTSTR to_T(LPCSTR pStr);

#ifdef UNDER_CE
  #ifndef DEBUG
    #include <windows.h>
    extern DBGPARAM dpCurSettings;
  #endif
#else
    #include <windows.h>
    #include <tchar.h>
    #include <stdio.h>

    typedef struct _DBGPARAM {
	    TCHAR	lpszName[32];           // @field Name of module
	    TCHAR   rglpszZones[16][32];    // @field names of zones for first 16 bits
	    ULONG   ulZoneMask;             // @field Current zone Mask
    } DBGPARAM, *LPDBGPARAM;

    #ifndef DEBUG
      #ifdef _DEBUG
        #define DEBUG
      #endif
    #endif

    extern DBGPARAM dpCurSettings;
    void WINAPIV NKDbgPrintf(LPCTSTR lpszFmt, ...);

    #define RETAILMSG(cond,printf_exp)   \
       ((cond)?(NKDbgPrintf printf_exp),1:0)

    #define DEBUGZONE(n)  (dpCurSettings.ulZoneMask & (0x00000001<<(n)))

    #define RETAILREGISTERZONES(hMod)

    #ifdef DEBUG
        #define DEBUGMSG(cond,printf_exp)   \
           ((void)((cond)?(NKDbgPrintf printf_exp),1:0))
        
        #define DBGCHK(module,exp) \
           ((void)((exp)?1:(          \
               NKDbgPrintf ( _T("%s: DEBUGCHK failed in file %s at line %d \r\n"), \
                         module, _T(__FILE__) ,__LINE__ ),    \
               DebugBreak(), \
	           0  \
           )))

        #define DEBUGCHK(exp) DBGCHK(dpCurSettings.lpszName, exp)
        #define DEBUGREGISTER(hMod)
    #endif //DEBUG
#endif

#ifndef __FUNCTION__
#define __FUNCTION__ __FILE__
#endif

#ifdef UNICODE
  #define PREPT(x) L ## x
#else
  #define PREPT(x) x
#endif

#define TOTSTR(x) PREPT(x)
#define __TFUNCTION__ TOTSTR(__FUNCTION__)
#define __TMODULE__ TOTSTR(__MODULE__)
#define __TFILE__ TOTSTR(__FILE__)

#define ZONEMASK(n) (0x00000001<<(n))

#ifdef FULL_CONTEXT
  #define FUNC_ENTRY(fmt, ...)    RETAILMSG(ZONE_FUNCTION, (__TMODULE__ _T(": +[") __TFILE__ _T(":%d] ") __TFUNCTION__ _T("(") fmt _T(")+\r\n"), __LINE__, __VA_ARGS__))
  #define FUNC_EXIT(fmt, ...)     RETAILMSG(ZONE_FUNCTION, (__TMODULE__ _T(": -[") __TFILE__ _T(":%d] ") __TFUNCTION__ _T("(") fmt _T(")-\r\n"), __LINE__, __VA_ARGS__))
  #define LOGMSG(cond, fmt, ...)  RETAILMSG(cond, (__TMODULE__ _T(":  [") __TFILE__ _T(":%d] ") __TFUNCTION__ _T("> ") fmt, __LINE__, __VA_ARGS__))
#else
  #define FUNC_ENTRY(fmt, ...)    RETAILMSG(ZONE_FUNCTION, (__TMODULE__ _T(": +") __TFUNCTION__ _T("(") fmt _T(")+\r\n"), __VA_ARGS__))
  #define FUNC_EXIT(fmt, ...)     RETAILMSG(ZONE_FUNCTION, (__TMODULE__ _T(": -") __TFUNCTION__ _T("(") fmt _T(")-\r\n"), __VA_ARGS__))
  #define LOGMSG(cond, fmt, ...)  RETAILMSG(cond, (__TMODULE__ _T(":  ") __TFUNCTION__ _T("> ") fmt, __VA_ARGS__))
#endif
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/